//
//  GreetTextListViewController.m
//  ExtModule
//
//  Created by CPX on 2018/9/11.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "GreetTextListViewController.h"
#import "GreetCardApi.h"
#import "GreetCardModel.h"
#import "GreetTextCell.h"
#import "MSLGreetCardController.h"

/**
 祝福语列表controller
 author:王连友
 */
@interface GreetTextListViewController ()
<
UITableViewDelegate,
UITableViewDataSource
>
@property (nonatomic,strong)UITableView * tableView;
@property (nonatomic,strong)NSMutableArray  * dataSource;
@end

@implementation GreetTextListViewController

#pragma mark --- getter
- (NSMutableArray *)dataSource{
    if (!_dataSource){
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

}

- (void)initViews{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0,100,100) style:UITableViewStylePlain];
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass(GreetTextCell.class) bundle:nil] forCellReuseIdentifier:NSStringFromClass(GreetTextCell.class)];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(NavHeight);
        make.leading.mas_equalTo(0);
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    
    
    
}

- (void)initNavigation{

    [self initDefaultNavigation];
    [self.myNavigationBar.backButton setTitle:TLString(@"grt_card") forState:UIControlStateNormal];
    self.myNavigationBar.backButton.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    
}
- (void)loadData{
    [GreetCardApi getCliffordTextListJsonArrayWithModelClass:[GreetTextModel class]
                                              NormalResponse:^(NSInteger status, id data, NSMutableArray *array) {
                                                  [self.dataSource addObjectsFromArray:array];
                                                  [self.tableView reloadData];
    } exceptionResponse:^(NSError *error) {
        
    }];
}
#pragma mark -- UITableViewDataSource,UITableViewDelegate
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    GreetTextCell  * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(GreetTextCell.class)];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    GreetTextModel * model = self.dataSource[indexPath.row];
    cell.model = model;
    return cell;

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    GreetTextModel  *model = self.dataSource[indexPath.row];
    [self logEvent:@"gc_click_images_greeting" params:@{@"greetingid":model.clifford_text}];
    MSLGreetCardController * cardEdit = [[MSLGreetCardController alloc]init];
    cardEdit.text_model =  model;
    cardEdit.image_model =  self.model;
    [self.navigationController pushViewController:cardEdit animated:YES];
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
